package com.qyhl.party.party.study.subject.item;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.qyhl.party.R;
import com.qyhl.webtv.basiclib.utils.StringUtils;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.news.NewsBean;
import com.zhy.adapter.recyclerview.base.ItemViewDelegate;
import com.zhy.adapter.recyclerview.base.ViewHolder;

public class PartyNewsNormalItemDelegate implements ItemViewDelegate<NewsBean> {
    private Context context;

    public PartyNewsNormalItemDelegate(Context context) {
        this.context = context;
    }

    @Override
    public int getItemViewLayoutId() {
        return R.layout.party_item_news_normal;
    }

    @Override
    public boolean isForViewType(NewsBean item, int position) {
        return (item.getPluralPicsFlag() == 1 && (item.getImagess() == null || item.getImagess().size() < 1))
                || (item.getPluralPicsFlag() != 1 && StringUtils.isEmpty(item.getLogo()));
    }

    @Override
    public void convert(ViewHolder holder, NewsBean newsBean, int position) {
        holder.setText(R.id.title, newsBean.getTitle());

        if (StringUtils.isNotEmpty(newsBean.getSource())) {
            holder.setVisible(R.id.origin, true);
            holder.setText(R.id.origin, newsBean.getSource());
        } else {
            holder.setVisible(R.id.origin, false);
        }

        try {
            int minPlay = Integer.parseInt(CommonUtils.getInstance().getMinPlay());
            if (minPlay == 0) {
                holder.setVisible(R.id.scan_num, false);
            } else {
                //判断评论数是否大于最少浏览数
                if (StringUtils.isEmpty(newsBean.getHitCount() + "")) {
                    holder.setVisible(R.id.scan_num, false);
                } else if (Integer.parseInt(newsBean.getHitCount()) >=
                        minPlay) {
                    holder.setText(R.id.scan_num, StringUtils.transformNum(newsBean.getHitCount()) + "阅");
                    holder.setVisible(R.id.scan_num, true);
                } else {
                    holder.setVisible(R.id.scan_num, false);
                }
            }

        } catch (Exception e) {
            holder.setVisible(R.id.scan_num, false);
        }
        
    }
}
